﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProductionLine.API.Application.Command.Dispatch;
using ProductionLine.Domain.Dispatch;
using ProductionLine.Domain.Team;
using ProductionLine.ErrorCode;
using ProductionLine.Extensions;

namespace ProductionLine.API.Controllers
{
    /// <summary>
    /// 派工
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class DispatchController : ControllerBase
    {
        IMediator mediator;
       ILogger<DispatchController> logger;

        public DispatchController(IMediator mediator, ILogger<DispatchController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 班组
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<TeamModel>>> GetTeam([FromQuery]GetTeamCommand request)
        {
            logger.LogInformation("查询车间信息成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 工单任务-派工
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
       
        public Task<APIResult<List<TaskDispatchModel>>> GetDispatch([FromQuery]GetDispatchCommand request)
        {
            logger.LogInformation("查询工单任务成功");
            return mediator.Send(request);
        }
        /// <summary>
        /// 新增派单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> AddDispatch(AddDispatchCommand request)
        {
            logger.LogInformation("新增工单任务成功");
            return await mediator.Send(request);
        }
    }
}
